//
//  Animation.m
//  UI02_homework02
//
//  Created by aaaaaa on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Animation.h"

@implementation Animation

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


+ (instancetype)animationWithImageName:(NSString *)imageName withImageFormat:(NSString *)imageFormat withStartCount:(NSInteger)startCount withImageCount:(NSInteger)imageCount withImageFrame:(CGRect)frame{
    NSMutableArray<UIImage *> *array = [NSMutableArray arrayWithCapacity:0];
    for (NSInteger i = 0; i < imageCount ; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%ld.%@", imageName, i + startCount , imageFormat]];
        [array addObject:image];
        [image release];
    }
    Animation *imageView = [[Animation alloc] init];
    imageView.frame = frame;
    imageView.animationImages = array;
    imageView.animationRepeatCount = 0;
//    imageView.animationDuration = imageCount  * imageView.frequency;
    imageView.userInteractionEnabled = YES;
    [imageView startAnimating];
    return [imageView autorelease];
}



+ (instancetype)createFlowerWithFrame:(CGRect)frame{
    Animation *flower = [Animation animationWithImageName:@"flower" withImageFormat:@"tiff" withStartCount:1 withImageCount:18 withImageFrame:frame];
    return flower;
}

+ (instancetype)createGuaWithFrame:(CGRect)frame{
    Animation *gua = [Animation animationWithImageName:@"gua" withImageFormat:@"tiff" withStartCount:1 withImageCount:16 withImageFrame:frame];
    return gua;
}

+ (instancetype)createPlantsWithFrame:(CGRect)frame{
    Animation *plants = [Animation animationWithImageName:@"plants" withImageFormat:@"tiff" withStartCount:1 withImageCount:9 withImageFrame:frame];
    return plants;
}

+ (instancetype)createZombieWithFrame:(CGRect)frame{
    Animation *zombie = [Animation animationWithImageName:@"Zombie" withImageFormat:@"tiff" withStartCount:0 withImageCount:22 withImageFrame:frame];
    return zombie;
}

+ (instancetype)createBZombieWithFrame:(CGRect)frame{
    Animation *bZombie = [Animation animationWithImageName:@"BZombie" withImageFormat:@"tiff" withStartCount:1 withImageCount:25 withImageFrame:frame];
    return bZombie;
}

















@end
